package com.xigua.JucOfBeautiful.chapterTen._10_1_CountDownLatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/139:24
 */
public class JoinDwonLatch2 {

    private static volatile CountDownLatch countDownLatch = new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        executorService.submit(()->{
            try {
                Thread.sleep(1000);
                System.out.println("childOne over");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                countDownLatch.countDown();
            }
        });
        executorService.submit(()->{
            try {
                Thread.sleep(1000);
                System.out.println("childTwo over");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                countDownLatch.countDown();
            }
        });
        System.out.println("wait all childThread over");
        countDownLatch.await();
        System.out.println("all childThread over");
        executorService.shutdown();
    }

}
